<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .father{
            width: 200px;
            height: 200px;
            background-color: pink;
            margin: 100px;
            position: relative;
        }
        .son{
            width: 100px;
            height: 100px;
            background-color: purple;
            margin-left: 45px;
        }
        .box{
            width: 200px;
            height: 200px;
            background-color: red;
            margin: 300px auto;
        }
    </style>
</head>
<body>
    <div class="father">
        <div class="son"></div>
    </div>

    <div class="box"></div>
    <script>
        var father = document.querySelector('.father');
        var son = document.querySelector('.son');
        //offset 得到元素的偏移、位置 返回不带单位的数值
        console.log(father.offsetTop);
        console.log(father.offsetLeft);

        //带有定位的父类为准
        console.log(son.offsetLeft);

        var box = document.querySelector('.box');
        //得到元素宽度、高度  padding border width
        console.log(box.offsetWidth);
        console.log(box.offsetHeight);

        //返回带有定位的父亲 ，否则返回body
        console.log(son.offsetParent);
        //返回亲爸
        console.log(son.parentNode);
    </script>
</body>
</html>